/**
 *
 * Copyright (C), 2002-2017, è½¦å›½ç½‘.
 */
package main;

import java.util.List;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.XmlElement;

/**
 * 生成insert主键
 * @author zhangweifeng
 * @version $Id: PagePlugin.java, v 0.1 2017年12月8日 上午10:50:09 zhangweifeng Exp $
 */
public class KeyPlugin extends PluginAdapter {

	@Override
	public boolean validate(List<String> list) {
		return true;
	}
	
	/** 
	 * @param element
	 * @param introspectedTable
	 * @return
	 * @see org.mybatis.generator.api.PluginAdapter#sqlMapInsertElementGenerated(org.mybatis.generator.api.dom.xml.XmlElement, org.mybatis.generator.api.IntrospectedTable)
	 */
	@Override
	public boolean sqlMapInsertElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
        Attribute useGeneratedKeys=new Attribute("useGeneratedKeys", "true");
		element.addAttribute(useGeneratedKeys);
		String keyPropertyValue=introspectedTable.getContext().getProperty("keyProperty");
        Attribute keyProperty=new Attribute("keyProperty", keyPropertyValue);
		element.addAttribute(keyProperty);
		return true;
	}
	
	/** 
	 * @param element
	 * @param introspectedTable
	 * @return
	 * @see org.mybatis.generator.api.PluginAdapter#sqlMapInsertSelectiveElementGenerated(org.mybatis.generator.api.dom.xml.XmlElement, org.mybatis.generator.api.IntrospectedTable)
	 */
	@Override
	public boolean sqlMapInsertSelectiveElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
        Attribute useGeneratedKeys=new Attribute("useGeneratedKeys", "true");
		element.addAttribute(useGeneratedKeys);
		String keyPropertyValue=introspectedTable.getContext().getProperty("keyProperty");
        Attribute keyProperty=new Attribute("keyProperty", keyPropertyValue);
		element.addAttribute(keyProperty);
		return true;
	}

}
